﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.Configuration;
using System.ComponentModel.DataAnnotations;
using TracNghiem.Models;
using System.Collections.ObjectModel;
using System.Web.Mvc;
using System.Data.OracleClient;

namespace TracNghiem.Areas.Admin.Models
{
    public class DonviModel
    {
        public string id { get; set; }        
        public string name { get; set; }
        public List<DonviModel> getDonvi()
        {
            List<DonviModel> Donvi = new List<DonviModel>();
            string sql = "";
            sql = "SELECT * FROM donvi_view";
            OracleDataReader odr = General.Lib_GetDataReader(sql);
            while (odr.Read())
            {
                Donvi.Add(new DonviModel { id = odr["id"].ToString(), name = odr["ten_don_vi"].ToString() });
            }
            General.conn_global.Close();
            return Donvi;
        }
    }
    public class DichvuModel
    {
        public string id { get; set; }
        public string name { get; set; }
        public string parent_id { get; set; }
        public string group_id { get; set; }

        public List<DichvuModel> getDichvu()
        {
            List<DichvuModel> Dichvu = new List<DichvuModel>();
            string sql = "";
            sql = "SELECT * FROM dichvu order by name";
            OracleDataReader odr = General.Lib_GetDataReader(sql);
            while (odr.Read())
            {
                Dichvu.Add(new DichvuModel { id = odr["id"].ToString(), name = odr["name"].ToString(), parent_id = odr["parent_id"].ToString() });
            }
            General.conn_global.Close();
            return Dichvu;
        }
        public List<DichvuModel> getDichvu_byid(int id,int groupid)
        {
            List<DichvuModel> Dichvu = new List<DichvuModel>();
            string sql = "";
            sql = "SELECT * FROM dichvu where PARENT_ID=" + id;            
            OracleDataReader odr = General.Lib_GetDataReader(sql);
            while (odr.Read())
            {
                Dichvu.Add(new DichvuModel { id = odr["id"].ToString(), name = odr["name"].ToString(), parent_id = odr["parent_id"].ToString(), group_id = odr["group_id"].ToString() });
            }
            General.conn_global.Close();
            return Dichvu;
        }
        public List<DichvuModel> getDichvu_byid2(int id, int groupid)
        {
            List<DichvuModel> Dichvu = new List<DichvuModel>();
            string sql = "";
            if (groupid == 0)
            {
                sql = "SELECT * FROM dichvu where PARENT_ID=" + id + "and group_id=1";
            }
            else
            {
                sql = "SELECT * FROM dichvu where PARENT_ID=" + id + "and group_id=" + groupid;
            }
            OracleDataReader odr = General.Lib_GetDataReader(sql);
            while (odr.Read())
            {
                Dichvu.Add(new DichvuModel { id = odr["id"].ToString(), name = odr["name"].ToString(), parent_id = odr["parent_id"].ToString(), group_id = odr["group_id"].ToString() });
            }
            General.conn_global.Close();
            return Dichvu;
        }
        public List<DichvuModel> getDichvuById(int id)
        {
            List<DichvuModel> Dichvu = new List<DichvuModel>();
            string sql = "";
            sql = "SELECT * FROM dichvu where ID =" + id;
            OracleDataReader odr = General.Lib_GetDataReader(sql);
            while (odr.Read())
            {
                Dichvu.Add(new DichvuModel { id = odr["id"].ToString(), name = odr["name"].ToString(), parent_id = odr["parent_id"].ToString() });
            }
            General.conn_global.Close();
            return Dichvu;
        }

      
    }
    public class Phanloai_TNModel
    {
        public string id { get; set; }
        public string name { get; set; }
        public List<Phanloai_TNModel> getPhanloai_TN()
        {
            List<Phanloai_TNModel> Phanloai_TN = new List<Phanloai_TNModel>();
            string sql = "";
            sql = "SELECT * FROM phanloai_tn order by name";
            OracleDataReader odr = General.Lib_GetDataReader(sql);
            while (odr.Read())
            {
                Phanloai_TN.Add(new Phanloai_TNModel { id = odr["id"].ToString(), name = odr["name"].ToString() });
            }
            General.conn_global.Close();
            return Phanloai_TN;
        }
    }
}